package com.fang.Utils;

import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.Date;

public class MyUtils {
    public static Date String2Date(String strDate,String strPattern){
        Date date = null;
        if(strDate != null && !strDate.equals("")){
            strPattern = strPattern == null ? "yyyy-MM-dd HH:mm:ss":strPattern;
            SimpleDateFormat sdf = new SimpleDateFormat(strPattern);
            try {
                date = sdf.parse(strDate);
            } catch (ParseException e) {
                e.printStackTrace();
            }
        }
        return date;
    }
    public static String Date2String(Date date,String strPattern){
        String strDate = null;
        if(date != null && !date.equals("")){
            strPattern = strPattern == null ? "yyyy-MM-dd HH:mm:ss":strPattern;
            SimpleDateFormat sdf = new SimpleDateFormat();
            strDate = sdf.format(date);
        }
        return strDate;
    }
}
